//
// Created by none98 on 2021/9/22.
//

#ifndef LOGINSERVER_CONTEXT_H
#define LOGINSERVER_CONTEXT_H

#include <mysql/jdbc/cppconn/connection.h>
#include "TcpConnection.h"

class GameServer;
class PlayerBin;
class Context{
public:
    Context(GameServer* server);
    ~Context() = default;

    long GetUid(){
        return uid;
    }

    void SetUid(long uid){
        this->uid = uid;
    }

    bool GetCreated() {
        return created;
    }

    void SetCreated(bool created){
        this->created = created;
    }

    void Register(long uid,TcpConnectionPtr conn);

    void SumbitTask(const std::function<void()> &func);

    sql::Connection* GetDbConnection();
    void CloseDbConnection(sql::Connection* conn);

    PlayerBin* GetPlayerBin(){
        return playBin.get();
    }

    void Synchronize();
private:
    //uid > 0
    long uid;
    bool created;
    GameServer* server;
    std::unique_ptr<PlayerBin> playBin;
};


#endif //LOGINSERVER_CONTEXT_H
